<?php
class ControllerMyplanAddplan extends Controller{
	public function index(){
		
		$this->data["user_id"]=$this->user->getId();
		
		$this->data["home"]=$this->url->link("myplan/myplanhome");
		$this->data["action"]=$this->url->link("myplan/addplan/addplan");
		
		$this->load->model("myplan/plan");
		$this->data["plan_types"]=$this->model_myplan_plan->getPlanTypes();
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/myplan/addplan.tpl')) 		            {
				$this->template = $this->config->get('config_template') . '/template/myplan/addplan.tpl';
			} else {
				$this->template = 'default/template/myplan/addplan.tpl';
			}
			
			$this->children = array(
			'myplancommon/footer',
			'myplancommon/header'
			);
											
			$this->response->setOutput($this->render());
	}	
	
	public function addplan(){
		    
		if($this->request->server["REQUEST_METHOD"]=="POST"){
		    $this->load->model("myplan/plan");	
			if($this->validate()){
			   $this->model_myplan_plan->addPlan($this->request->post); 
			   $this->session->data["success"]="添加计划成功.";
			   $this->redirect($this->url->link("myplan/myplanhome"));
			}
			
			$this->index();

		}
	}
	
	public function validate(){
		if($this->request->post["content"]==""){
			$this->data["warning"]="不能为空";
			return false;
		}
	    return true;
	}
}
?>
